package com.ruoyi.web.controller.ufox;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ufox.domain.BisDeviceSwitchLog;
import com.ruoyi.ufox.service.IBisDeviceSwitchLogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 设备开关日志Controller
 * 
 * @author ufoxs
 * @date 2022-08-17
 */
@RestController
@RequestMapping("/bussiness/switchlog")
public class BisDeviceSwitchLogController extends BaseController
{
    @Autowired
    private IBisDeviceSwitchLogService bisDeviceSwitchLogService;

    /**
     * 查询设备开关日志列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:switchlog:list')")
    @GetMapping("/list")
    public TableDataInfo list(BisDeviceSwitchLog bisDeviceSwitchLog)
    {
        startPage();
        List<BisDeviceSwitchLog> list = bisDeviceSwitchLogService.selectBisDeviceSwitchLogList(bisDeviceSwitchLog);
        return getDataTable(list);
    }

    /**
     * 导出设备开关日志列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:switchlog:export')")
    @Log(title = "设备开关日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BisDeviceSwitchLog bisDeviceSwitchLog)
    {
        List<BisDeviceSwitchLog> list = bisDeviceSwitchLogService.selectBisDeviceSwitchLogList(bisDeviceSwitchLog);
        ExcelUtil<BisDeviceSwitchLog> util = new ExcelUtil<BisDeviceSwitchLog>(BisDeviceSwitchLog.class);
        util.exportExcel(response, list, "设备开关日志数据");
    }

    /**
     * 获取设备开关日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:switchlog:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return AjaxResult.success(bisDeviceSwitchLogService.selectBisDeviceSwitchLogByLogId(logId));
    }

    /**
     * 新增设备开关日志
     */
    @PreAuthorize("@ss.hasPermi('bussiness:switchlog:add')")
    @Log(title = "设备开关日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BisDeviceSwitchLog bisDeviceSwitchLog)
    {
        return toAjax(bisDeviceSwitchLogService.insertBisDeviceSwitchLog(bisDeviceSwitchLog));
    }

    /**
     * 修改设备开关日志
     */
    @PreAuthorize("@ss.hasPermi('bussiness:switchlog:edit')")
    @Log(title = "设备开关日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BisDeviceSwitchLog bisDeviceSwitchLog)
    {
        return toAjax(bisDeviceSwitchLogService.updateBisDeviceSwitchLog(bisDeviceSwitchLog));
    }

    /**
     * 删除设备开关日志
     */
    @PreAuthorize("@ss.hasPermi('bussiness:switchlog:remove')")
    @Log(title = "设备开关日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(bisDeviceSwitchLogService.deleteBisDeviceSwitchLogByLogIds(logIds));
    }
}
